<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "section".
 *
 * @property string $id
 * @property string $section_name
 * @property string $created_at
 * @property string $updated_at
 * @property integer $is_usable
 */
class Section extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'section';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['created_at', 'updated_at', 'is_usable'], 'integer'],
            [['section_name'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'section_name' => '部门名称',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    /**
     * 数据保存前
     * @param bool $insert
     * @return bool
     */
    public function beforeSave($insert)
    {
        if(parent::beforeSave($insert))
        {
            if($insert)
            {
                $this->created_at = time();
            }
                $this->updated_at = time();
            return true;
        }
        else
        {
            return false;
        }
    }

}
